package studio.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import studio.excepcion.DAOExcepcion;
import studio.modelo.Sala;
import studio.negocio.SeguridadSala;

import junit.framework.Assert;

/**
 * Servlet implementation class SalaBusServlet
 */
public class SalaBusServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SalaBusServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.processRequest(request, response);
	}
	
	
	protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	//	SeguridadSala objSala= new  SeguridadSala();
		SeguridadSala n = new SeguridadSala();
		try{
			System.out.println("No se ha  ddddd");
			 String cmbSala=request.getParameter("cmbSala");
			 String cmblocal=request.getParameter("cmblocal");
			 String cmbcapacidad=request.getParameter("cmbcapacidad");
			 System.out.println(cmbSala);
			 System.out.println(cmblocal);
			 System.out.println(cmbcapacidad);
			
		    //BUSCAR este funciona
			//Collection<Sala> ListarSala = n.buscarSala(txtbuscaSala);
			 Collection<Sala> ListarSala = n.buscarSala2(cmbSala, cmblocal, cmbcapacidad);
								
	     	if (ListarSala.size()>0)
	     	{
			//SI SE ENCUENTRA CONCORDANCIA SE MUESTRA
	     		System.out.println("No se ha encontrado ddddd");
		     	request.setAttribute("Salas", ListarSala);
			    }
		    else
			//SI NO SE ENCUENTRA MUESTRA MENSAJE
			{ System.out.println("No se ha encontrado la Sala con la busqueda"); 
			};
		} 
		catch (DAOExcepcion e) 
		{
		   Assert.fail("Fallo: " + e.getMessage());
		}
	
		RequestDispatcher rd = request.getRequestDispatcher("/BuscarSala.jsp");
		rd.forward(request, response);
	}	


}
